<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="跳转类型" prop="skipType">
        <el-select v-model="queryParams.skipType" placeholder="请选择跳转类型" clearable
                   size="small">
          <el-option
            v-for="dict in skipTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable
                   size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['basic:banner:add']">
          新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                   v-hasPermi="['basic:banner:remove']">
          删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="图片" align="center" prop="image">
        <template slot-scope="scope">
          <el-image
            style="width: 80px; height: 80px"
            :src="scope.row.image"
            :preview-src-list="[scope.row.image]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="跳转类型" align="center" prop="skipType"
                       :formatter="skipTypeFormat"/>
      <el-table-column label="跳转参数" align="center" prop="skipValue"/>
      <el-table-column label="优先级" align="center" prop="sort"/>
      <el-table-column label="状态" align="center" prop="status"
                       :formatter="statusFormat"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['basic:banner:edit']">
            修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['basic:banner:remove']">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="pageNum"
      :limit.sync="pageSize"
      @pagination="getList"/>

    <add-or-update v-show="open" @on-close="open=false" ref="addOrUpdate"></add-or-update>
  </div>
</template>

<script>
  import {
    listBanner,
    getBanner,
    delBanner,
    exportBanner
  } from '@/api/basic/banner'
  import mixinViewModule from '@/mixins/view-module'
  import AddOrUpdate from './add-or-update'

  export default {
    name: 'Banner',
    mixins: [mixinViewModule],
    components: { AddOrUpdate },
    data() {
      return {
        mixinViewModuleOptions: {
          getDetailsURL: getBanner,// 查询详情实体
          getDataListURL: listBanner, // 数据列表接口，API地址
          deleteURL: delBanner, // 删除接口，API地址
          tableKey: 'id', // 删除接口，批量状态下由那个key进行标记操作？比如：pid，uid...
          exportURL: exportBanner // 导出接口，API地址
        },
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        // 跳转类型;1=无跳转,2=跳转url,3=跳转商品字典
        skipTypeOptions: [],
        // 0=正常,1=停用字典
        statusOptions: [],
        // 查询参数
        queryParams: {
          image: null
          , skipType: null
          , skipValue: null
          , sort: null
          , status: null
          , orderByColumn: 't.sort'
          , isAsc: 'desc'
        }
      }

    },
    created() {
      this.getList()
      this.getDicts('banner_skip_type').then(response => {
        this.skipTypeOptions = response.data
        this.$refs.addOrUpdate.skipTypeOptions = response.data
      })
      this.getDicts('sys_normal_disable').then(response => {
        this.statusOptions = response.data
        this.$refs.addOrUpdate.statusOptions = response.data
      })
    },
    methods: {
      // 跳转类型;1=无跳转,2=跳转url,3=跳转商品字典翻译
      skipTypeFormat(row, column) {
        return this.selectDictLabel(this.skipTypeOptions, row.skipType)
      },
      // 0=正常,1=停用字典翻译
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.status)
      },
      //打开dislog前执行
      onOpenHandleDialog() {

      },
      //打开删除前执行
      onHandleDetails(data, type) {
        if (type == this.$formType.edit) {
          this.$refs.addOrUpdate.form = data.data
        }
      },
      //开始查询列表的时候
      onStartQuery() {

      },
      //开始重制查询前执行
      onResetQuery() {

      }
    }
  }
</script>
